<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>3.购物车</title>
  <style>
    table {
      margin: 100px auto;
      width: 800px;
      border-collapse: collapse;
    }

    th {
      background-color: #0094ff;
      color: #fff;
    }

    td,
    th {
      text-align: center;
      border: 1px solid black;
      height: 30px;
      font-size: 18px;
    }
  </style>
</head>

<body>
  <div id="app">
    <table>
      <tr>
        <th>编号</th>
        <th>品牌名称</th>
        <th>创立时间</th>
        <th>操作</th>
      </tr>
      <tr v-for="item in list" :key="item.id">
        <td>{{item.id}}</td>
        <td>{{item.name}}</td>
        <td>{{item.time}}</td>
        <td><button @click="del(item.id)">删除</button></td>
      </tr>
      <tr v-show="list.length===0">
        <td colspan="4">没有数据咯~</td>
      </tr>
    </table>
  </div>
  <script src="../vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        list: [
          { id: 1, name: '奔驰', time: '2024-5-1' },
          { id: 2, name: '宝马', time: '2024-5-2' },
          { id: 3, name: '奥迪', time: '2024-5-3' },
        ]
      },
      methods: {
        del(id) {
          this.list = this.list.filter(item => item.id !== id)
        }
      }
    })
  </script>
</body>

</html>